package cn.mogugo;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.mogugo.comm.BaseAction;

public class LoginAction extends BaseAction{
	
	public ActionForward login(ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception{
		LoginForm lf = (LoginForm)form;
		String username = lf.getUser_name();
		String userpass = lf.getUser_pass();
		
		if(username.equals("abc") && userpass.equals("123")){
			request.getSession().setAttribute("loginsucc", 1);
			return mapping.findForward("succ");
		}else{
			
			try{
	    		response.setContentType("text/html; charset=UTF-8");
	            response.setHeader("Cache-Control","no-cache");
	            PrintWriter out = response.getWriter();
	            //返回文件路径到文本框
	            out.println("<script type=\"text/javascript\">");
	            out.println("javascript:alert(\"账号密码不匹配。\");");
	            out.println("javascript:history.back();");
	            out.println("</script>");
	            out.flush();
	            out.close();
	    	}catch(IOException e){
	    		
	    	}finally{
	    		
	    	}
			
			return null;
		}
	}
	
	public ActionForward index(ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception{
		return mapping.findForward("index");
	}
	
	
	public ActionForward main(
            ActionMapping mapping,
            ActionForm form, 
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
		return mapping.findForward("main");
	}
	
	
	public ActionForward header(
            ActionMapping mapping,
            ActionForm form, 
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
		return mapping.findForward("header");
	}
	
	
	public ActionForward content(
            ActionMapping mapping,
            ActionForm form, 
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
		return mapping.findForward("content");
	}
	
}
